<template>
	<view class="ChooseTime">
		<!-- <uni-section :title="'日期时间范围用法：' + '[' + datetimerange + ']' " type="line"></uni-section> -->
		<view class="example-body">
			<uni-datetime-picker v-model="datetimerange" type="datetimerange" rangeSeparator="至" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				single: '',
				datetimesingle: '',
				range: [],
				datetimerange: [],
				lastdate: '',
				currentdate: '',
				start: Date.now() - 1000000000,
				end: Date.now() + 1000000000
			};
		},
		watch: {
			datetimesingle(newval) {
				// console.log('单选:', this.datetimesingle);
			},
			range(newval) {
				// console.log('范围选:', this.range);
			},
			datetimerange(newval) {
				// console.log('范围选:', this.datetimerange);
				uni.setStorageSync('chooseDate',this.datetimerange)
			}
		},
		mounted() {
			setTimeout(() => {
				// 获取当前日期时间
				const now = new Date();
				// 获取年月日时分秒
				const year = now.getFullYear(); // 年份
				const month = now.getMonth() + 1; // 月份，+1因为getMonth()返回0-11
				const date = now.getDate(); // 日期
				const hours = now.getHours(); // 小时
				const minutes = now.getMinutes(); // 分钟
				const seconds = now.getSeconds(); // 秒钟
				// 当前年月日
				let nowdate = `${year}-${month}-${date}`
				// 当前年月日时分秒
				let currentdate = `${year}-${month}-${date} ${hours}:${minutes}:${seconds}`
				// 昨天年月日时分秒
				let lastdate = `${year}-${month}-${date - 1} ${hours}:${minutes}:${seconds}`
				this.datetimesingle = Date.now() - 2 * 24 * 3600 * 1000
				this.single = nowdate
				this.datetimerange = [lastdate, currentdate]
			}, 1000)
		},

		methods: {
			aaa() {
				// this.datetimerange
				// console.log('bei diaoyle' + this.datetimerange);
				uni.setStorageSync('chooseDate', this.datetimerange)
			},
			change(e) {
				this.single = e
				// console.log('change事件:', this.single = e);
			},
			changeLog(e) {
				// console.log('change事件:', e);
			},
			maskClick(e) {
				// console.log('maskClick事件:', e);
			}
		}
	}
</script>

<style lang="scss">
	.ChooseTime {}
</style>